/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.duty.web;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.duty.entity.ZlmtInoutReg;
import com.thinkgem.jeesite.modules.duty.service.ZlmtInoutRegService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 出入登记管理Controller
 * @author johnKee
 * @version 2016-07-17
 */
@Controller
@RequestMapping(value = "${adminPath}/duty/zlmtInoutReg")
public class ZlmtInoutRegController extends BaseController {

	@Autowired
	private ZlmtInoutRegService zlmtInoutRegService;
	
	@ModelAttribute
	public ZlmtInoutReg get(@RequestParam(required=false) String id) {
		ZlmtInoutReg entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = zlmtInoutRegService.get(id);
		}
		if (entity == null){
			entity = new ZlmtInoutReg();
		}
		return entity;
	}
	

	@RequestMapping(value = {"list", ""})
	public String list(ZlmtInoutReg zlmtInoutReg, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ZlmtInoutReg> page = zlmtInoutRegService.findPage(new Page<ZlmtInoutReg>(request, response), zlmtInoutReg);
		model.addAttribute("page", page);
		return "modules/duty/zlmtInoutRegList";
	}

	@RequestMapping(value = "form")
	public String form(ZlmtInoutReg zlmtInoutReg, Model model) {
		model.addAttribute("zlmtInoutReg", zlmtInoutReg);
		return "modules/duty/zlmtInoutRegForm";
	}

	@RequestMapping(value = "save")
	public String save(ZlmtInoutReg zlmtInoutReg, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, zlmtInoutReg)){
			return form(zlmtInoutReg, model);
		}
		zlmtInoutRegService.save(zlmtInoutReg);
		addMessage(redirectAttributes, "保存出入记录成功");
		return "redirect:"+ Global.getAdminPath()+"/duty/zlmtInoutReg/?repage";
	}
	
	@RequestMapping(value = "delete")
	public String delete(ZlmtInoutReg zlmtInoutReg, RedirectAttributes redirectAttributes) {
		zlmtInoutRegService.delete(zlmtInoutReg);
		addMessage(redirectAttributes, "删除出入记录成功");
		return "redirect:"+ Global.getAdminPath()+"/duty/zlmtInoutReg/?repage";
	}

}